from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-21 14:13:52.921527
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 21, Sep, 2021
Time: 14:13:57
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.2971
Nobs: 421.000 HQIC: -46.8197
Log likelihood: 4641.09 FPE: 3.29724e-21
AIC: -47.1613 Det(Omega_mle): 2.66928e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.440310 0.092481 4.761 0.000
L1.Burgenland 0.100905 0.047761 2.113 0.035
L1.Kärnten -0.114533 0.023861 -4.800 0.000
L1.Niederösterreich 0.160573 0.102182 1.571 0.116
L1.Oberösterreich 0.117638 0.100381 1.172 0.241
L1.Salzburg 0.285921 0.050130 5.704 0.000
L1.Steiermark 0.027522 0.066544 0.414 0.679
L1.Tirol 0.109222 0.052762 2.070 0.038
L1.Vorarlberg -0.107847 0.047256 -2.282 0.022
L1.Wien -0.012673 0.091612 -0.138 0.890
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.011152 0.212817 0.052 0.958
L1.Burgenland -0.049417 0.109908 -0.450 0.653
L1.Kärnten 0.037186 0.054909 0.677 0.498
L1.Niederösterreich -0.216781 0.235140 -0.922 0.357
L1.Oberösterreich 0.483859 0.230997 2.095 0.036
L1.Salzburg 0.307874 0.115358 2.669 0.008
L1.Steiermark 0.116150 0.153131 0.758 0.448
L1.Tirol 0.314750 0.121416 2.592 0.010
L1.Vorarlberg 0.003629 0.108745 0.033 0.973
L1.Wien 0.003091 0.210817 0.015 0.988
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.245769 0.046968 5.233 0.000
L1.Burgenland 0.090045 0.024256 3.712 0.000
L1.Kärnten -0.001917 0.012118 -0.158 0.874
L1.Niederösterreich 0.212459 0.051895 4.094 0.000
L1.Oberösterreich 0.166064 0.050980 3.257 0.001
L1.Salzburg 0.034395 0.025459 1.351 0.177
L1.Steiermark 0.018948 0.033796 0.561 0.575
L1.Tirol 0.068623 0.026796 2.561 0.010
L1.Vorarlberg 0.057301 0.024000 2.388 0.017
L1.Wien 0.109925 0.046527 2.363 0.018
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.182242 0.045944 3.967 0.000
L1.Burgenland 0.048201 0.023727 2.031 0.042
L1.Kärnten -0.006551 0.011854 -0.553 0.581
L1.Niederösterreich 0.139095 0.050763 2.740 0.006
L1.Oberösterreich 0.316840 0.049869 6.353 0.000
L1.Salzburg 0.101294 0.024904 4.067 0.000
L1.Steiermark 0.131407 0.033059 3.975 0.000
L1.Tirol 0.076720 0.026212 2.927 0.003
L1.Vorarlberg 0.056600 0.023476 2.411 0.016
L1.Wien -0.046166 0.045512 -1.014 0.310
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.205983 0.091271 2.257 0.024
L1.Burgenland -0.049102 0.047136 -1.042 0.298
L1.Kärnten -0.034480 0.023549 -1.464 0.143
L1.Niederösterreich 0.107093 0.100845 1.062 0.288
L1.Oberösterreich 0.166183 0.099068 1.677 0.093
L1.Salzburg 0.253525 0.049474 5.124 0.000
L1.Steiermark 0.080204 0.065674 1.221 0.222
L1.Tirol 0.126012 0.052072 2.420 0.016
L1.Vorarlberg 0.116136 0.046638 2.490 0.013
L1.Wien 0.032293 0.090413 0.357 0.721
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.032323 0.070604 0.458 0.647
L1.Burgenland 0.022952 0.036463 0.629 0.529
L1.Kärnten 0.052592 0.018216 2.887 0.004
L1.Niederösterreich 0.210486 0.078010 2.698 0.007
L1.Oberösterreich 0.335542 0.076635 4.378 0.000
L1.Salzburg 0.044773 0.038271 1.170 0.242
L1.Steiermark -0.004879 0.050803 -0.096 0.923
L1.Tirol 0.113292 0.040281 2.813 0.005
L1.Vorarlberg 0.066121 0.036077 1.833 0.067
L1.Wien 0.127733 0.069940 1.826 0.068
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185094 0.086062 2.151 0.031
L1.Burgenland 0.017148 0.044446 0.386 0.700
L1.Kärnten -0.057385 0.022205 -2.584 0.010
L1.Niederösterreich -0.116518 0.095090 -1.225 0.220
L1.Oberösterreich 0.186726 0.093414 1.999 0.046
L1.Salzburg 0.030362 0.046650 0.651 0.515
L1.Steiermark 0.296319 0.061926 4.785 0.000
L1.Tirol 0.489027 0.049100 9.960 0.000
L1.Vorarlberg 0.077044 0.043976 1.752 0.080
L1.Wien -0.105379 0.085253 -1.236 0.216
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160506 0.094288 1.702 0.089
L1.Burgenland -0.012720 0.048694 -0.261 0.794
L1.Kärnten 0.063837 0.024327 2.624 0.009
L1.Niederösterreich 0.196794 0.104179 1.889 0.059
L1.Oberösterreich -0.128896 0.102343 -1.259 0.208
L1.Salzburg 0.237491 0.051109 4.647 0.000
L1.Steiermark 0.153111 0.067845 2.257 0.024
L1.Tirol 0.047250 0.053793 0.878 0.380
L1.Vorarlberg 0.131504 0.048180 2.729 0.006
L1.Wien 0.153499 0.093402 1.643 0.100
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488383 0.051024 9.572 0.000
L1.Burgenland -0.008760 0.026351 -0.332 0.740
L1.Kärnten -0.010018 0.013165 -0.761 0.447
L1.Niederösterreich 0.203039 0.056376 3.602 0.000
L1.Oberösterreich 0.259417 0.055383 4.684 0.000
L1.Salzburg 0.021909 0.027658 0.792 0.428
L1.Steiermark -0.023504 0.036714 -0.640 0.522
L1.Tirol 0.067337 0.029110 2.313 0.021
L1.Vorarlberg 0.058678 0.026072 2.251 0.024
L1.Wien -0.053444 0.050544 -1.057 0.290
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.022281 0.077849 0.143005 0.132165 0.044439 0.076534 -0.000686 0.179378
Kärnten 0.022281 1.000000 -0.044099 0.127803 0.047339 0.069675 0.455316 -0.092222 0.092504
Niederösterreich 0.077849 -0.044099 1.000000 0.283189 0.083490 0.264265 0.022103 0.138522 0.258868
Oberösterreich 0.143005 0.127803 0.283189 1.000000 0.180569 0.285893 0.157032 0.102386 0.140529
Salzburg 0.132165 0.047339 0.083490 0.180569 1.000000 0.126628 0.056964 0.106041 0.052754
Steiermark 0.044439 0.069675 0.264265 0.285893 0.126628 1.000000 0.132021 0.092428 -0.021576
Tirol 0.076534 0.455316 0.022103 0.157032 0.056964 0.132021 1.000000 0.045798 0.119703
Vorarlberg -0.000686 -0.092222 0.138522 0.102386 0.106041 0.092428 0.045798 1.000000 -0.046864
Wien 0.179378 0.092504 0.258868 0.140529 0.052754 -0.021576 0.119703 -0.046864 1.000000